import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';
import Confirm from 'vux/src/components/confirm/index.vue'

export default {
  name: 'courseDetails',
  components: {Confirm},
  data () {
    return {
      siteId: '',
      // 班级id
      id: '',
      studentId: '',
      studentName: '',
      content: {},
      isDisabled:false,
      signClass:'signUpBtn',
      agree: false,
      show: false
    }
  },
  mounted () {
    this.$router.afterEach((to, from, next) => {
      window.scrollTo(0, 0);
    });
    var _this = this
    var studertids = ''
    _this.siteId = window.sessionStorage.getItem('siteId')
    _this.studentId = window.sessionStorage.getItem('studentId')
    _this.id = window.sessionStorage.getItem('event_id')
    studertids = _this.studentId
    if (studertids == '-1') {
      studertids = ''
    }
    //console.log(1);
    http.post(CONSTANT.CLAZZVIEW, {
      siteId: _this.siteId,
      id: _this.id,
      studentId: studertids
    }, (res) => {
      _this.content = res
      _this.content.descript=_this.content.descript.substr(0,_this.content.descript.indexOf('报名协议'));
      //console.log(res);
    })
    _this.studentName = window.sessionStorage.getItem('studentName')
    if (_this.studentName == '-1') {
      http.post(CONSTANT.STUDENTVIEW, {
        siteId: this.siteId,
        studentId: this.studentId
      }, (res) => {
        _this.studentName = res.name
      })
    }
  },
  methods: {
    onCancel () {
      // 取消按钮
    },
    onConfirm () {
      var _this = this
      _this.$router.push({path: '/login'})
    },
    goSignUp () {
      var _this = this
      if (!_this.isDisabled) {
        _this.isDisabled = true
        _this.signClass = 'signUpNotBtn'
        if (_this.studentId == '-1') {
          _this.show = true
          return
        }
        if (_this.agree == false) {
          alert('请同意并接受《少年宫报名协议》！')
        } else {
          // 班级报名
          http.post(CONSTANT.CLASSAPPLY, {
            siteId: _this.siteId,
            clazzId: _this.id,
            studentId: _this.studentId
          }, (res) => {
            _this.isDisabled = false
            _this.signClass = 'signUpBtn'
            //console.log(res)
            if (res.msg) {
              alert(res.msg)
            } else if (res.result) {
              alert(res.result)
            } else if (res.tipMessage) {
              alert(res.tipMessage + '预约号：' + res.reserveNo)
              var query = {reserveNo:res.reserveNo,name:this.content.name,totalFees:res.applyFee,area:this.content.area,classNo:this.content.classNo,frontStatusName:this.content.frontStatusName,year:this.content.year,term:this.content.term,spelName:this.content.spelName,degree:this.content.degree,studentName:this.studentName}
              this.$router.push({path: '/payment',query:query})
            }
          })
        }
      }
    },
    agreeUp (e) {
      var _this = this
      //console.log(e.target.className)
      if (e.target.className == 'iconfont icon-yuanxingxuanzhongfill') {
        e.target.className = 'iconfont icon-yuanxingweixuanzhong'
        _this.agree = false
      } else {
        e.target.className = 'iconfont icon-yuanxingxuanzhongfill'
        _this.agree = true
      }
    },
    comeBack () {
      window.history.go(-1)
    }
  }
}
